'use strict'
let users=[
    {
        id:1,
        username:'admin1',
        password:'112',
        nickname:'超级管理员',
        avatar:'头像'
    },
    {
        id:2,
        username:'admin2',
        password:'112',
        nickname:'超级管理员',
        avatar:'头像'
    },
    {
        id:3,
        username:'admin3',
        password:'112',
        nickname:'超级管理员',
        avatar:'头像'
    },
]

let fn_index=async(ctx,next)=>{
    ctx.body=[
        {
            id:1,
            username:'admin1',
            nickname:'超级管理员'
        },
        {
            id:2,
            username:'admin2',
            nickname:'超级管理员'
        },
        {
            id:2,
            username:'admin2',
            nickname:'超级管理员'
        },
    ]
}

let fn_create=async(ctx,next)=>{
    let username=ctx.request.body.username
    let password=ctx.request.body.password
    let list=users.filter(item=>{
        return item.username===username && item.password===password
    })
    if(list.length>0){
        ctx.body={
            code:1000,
            data:list[0],
            msg:'登陆成功'
        }
    }else{
        ctx.body={
            code:400,
            data:'',
            msg:'用户名或密码错误，请重新输入'
        }
    }
}

module.exports={
    'post /user':fn_create,
    'get /user':fn_index,
    'post /login':fn_create
}